package com.java.awt;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GridLayoutClient {

	private Frame frame;
	private Button b1,b2,b3,b4,b5,b6;

	public void go(){
		frame = new Frame("Grid Layout");
		frame.setLayout(new GridLayout(3,2));//设置3*的网格
		b1= new Button("1");//设置button显示
		b1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println(e.getActionCommand());
			}
		});
		b2= new Button("2");
		b3= new Button("3");
		b4= new Button("4");
		b5= new Button("5");
		b6= new Button("6");
		frame.add(b1);//把b1添加到frame对象
		frame.add(b2);
		frame.add(b3);
		frame.add(b4);
		frame.add(b5);
		frame.add(b6);
		frame.pack();//压缩成最小大小
		frame.setVisible(true);
	}

	public static void main(String[] args) {
		GridLayoutClient grid = new GridLayoutClient();
		grid.go();
	}
}
